<template>
  <div class="bagerbtn-wrapper">
    <div class="bager-item"
      :class="{'bager-item-active': isActive === 'All'}"
      @click="handleClickItem('All')">
      <span class="label">{{bagerTitle?.labelone}}</span>
      <span class="icon-num" v-if="totalNum?.total">{{totalNum?.total}}</span>
    </div>
    <div class="bager-item bager-no-border"
    :class="{'bager-item-active': isActive === 'Arrived'}"
    @click="handleClickItem('Arrived')"
    >
      <span class="label">{{bagerTitle?.labeltwo}}</span>
      <span class="icon-num" v-if="totalNum?.arrived">{{totalNum?.arrived}}</span>
    </div>
    <div class="bager-item"
    :class="{'bager-item-active': isActive === 'NotArrived'}"
    @click="handleClickItem('NotArrived')"
    >
      <span class="label">{{bagerTitle?.labelthree}}</span>
      <span class="icon-num" v-if="totalNum?.notArrived">{{totalNum?.notArrived}}</span>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, PropType, ref } from '@vue/runtime-core';

type TotalNum = {
  total: number,
  arrived: number,
  notArrived: number
}
type BagerTitle = {
  labelone: string,
  labeltwo: string,
  labelthree: string
}
export default defineComponent({
  name: 'bagerbtn',
  props: {
    totalNum: {
      type: Object as PropType<TotalNum>
    },
    bagerTitle: {
      type: Object as PropType<BagerTitle>
    }
  },
  setup(props, {emit}) {
    const isActive = ref('All')
    const handleClickItem = (type: string) => {
      isActive.value = type
      emit('handleStatusSearch', type)
    }
    return {
      isActive,
      handleClickItem
    }
  }
})
</script>

<style lang="scss" scoped>
  .bagerbtn-wrapper {
    display: flex;
    height: 30px;
    box-sizing: border-box;
    
    .bager-item {
      width: 100px;
      border: 1px solid #dcdfe6;
      text-align: center;
      line-height: 30px;
      background-color: #fff;
      color: $primaryText;
      cursor: pointer;
      user-select: none;
      .label {

      }
      .icon-num {
        border-radius: 10px;
        background-color: #9397a2;
        color: white;
        padding: 2px 6px;
        font-size: 12px;
        margin-left: 5px;
      }
    }
    .bager-no-border {
      border-left: 0;
      border-right: 0;
    }

    .bager-item-active {
      background-color: $mainColor;
      color: #fff;

      .icon-num {
        background-color: #f56c6c;
        color: #fff;
      }
    }
  }
</style>